package com.to8to.kitt.esb;

import java.util.concurrent.ExecutorService;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;
import org.apache.curator.utils.ThreadUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ZK {
	
	public static Logger logger = LoggerFactory.getLogger(ZK.class);  
	
	public static String ZK_FILE = "zk.properties";
	
	public static ZkConfig ZK_CONFIG = new ZkConfig(ZK_FILE);
	
	public static CuratorFramework ZK_CLIENT;
	
	public static ExecutorService ZkCuratorThreadPool = ThreadUtils.newSingleThreadExecutor("zk-curator");
			//ThreadUtils.newFixedThreadPool(Constants.MAX_ZK_THREADS, "ZkCurator-threadpool"); //Executors.newFixedThreadPool(nthreads);
	
	static
	{
		logger.info("init zk client ... start!");
		ZK_CLIENT = CuratorFrameworkFactory.newClient(ZK_CONFIG.zkhosts,
				ZK_CONFIG.sessionTimeoutMs, ZK_CONFIG.connectionTimeoutMs,
				new RetryNTimes(ZK_CONFIG.maxRetries, ZK_CONFIG.baseSleepTimeMs));
		ZK_CLIENT.start();
		logger.info("zk client started!");
	}
	
//	public static void init(ZkConfig zkconfig)
//	{
//		ZK_CONFIG = zkconfig;
//		logger.info("init zk client ... start!");
//		ZK_CLIENT = CuratorFrameworkFactory.newClient(ZK_CONFIG.zkhosts,
//				ZK_CONFIG.sessionTimeoutMs, ZK_CONFIG.connectionTimeoutMs,
//				new RetryNTimes(ZK_CONFIG.maxRetries, ZK_CONFIG.baseSleepTimeMs));
//
//		ZK_CLIENT.start();
//		logger.info("zk client started!");
//	}
	
}
